package com.ymatou.iapi.userservice.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.enums.AppSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.ChannelSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.TerminalSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.UserTypeEnum;
import com.ymatou.iapi.userservice.parameter.enums.VisitLanguageEnum;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.req.VerifyLoginPwdByLoginIdReq;
import com.ymatou.iapi.userservice.service.CreateUserCall;
import com.ymatou.iapi.userservice.service.VerifyLoginPwdByLoginIdTypeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.model.Userinfoex;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.DesUtil;
import com.ymttest.utils.TestDataManager;
/**
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_VerifyLoginPwdByLoginIdType{
	private static VerifyLoginPwdByLoginIdReq verifyLoginPwdByLoginIdReq;
	private static VerifyLoginPwdByLoginIdTypeCall verifyLoginPwdByLoginIdTypeCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("验证登入密码接口");
	}

	@Before
	public void caseUp() {
		verifyLoginPwdByLoginIdReq=new VerifyLoginPwdByLoginIdReq();
		verifyLoginPwdByLoginIdTypeCall=new VerifyLoginPwdByLoginIdTypeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(verifyLoginPwdByLoginIdTypeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_VerifyLoginPwdByLoginIdType_001() {
		Logger.start(true,"验证登入密码成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid=JUserCallService.createUserCall(cur);
			verifyLoginPwdByLoginIdReq.setAppId("autotest");
			verifyLoginPwdByLoginIdReq.setClientIp(cur.getClientIp());
			verifyLoginPwdByLoginIdReq.setLoginId(cur.getLoginId());
			verifyLoginPwdByLoginIdReq.setPwd(cur.getLoginPassword());
			verifyLoginPwdByLoginIdTypeCall.setData(verifyLoginPwdByLoginIdReq);
			verifyLoginPwdByLoginIdTypeCall.callService();
			Logger.verifyEquals("true", verifyLoginPwdByLoginIdTypeCall.getString("Success"), "验证Success");
			Logger.verifyEquals(uid, verifyLoginPwdByLoginIdTypeCall.getJsonObject().get("Result").getAsJsonObject().get("userId").getAsInt(), "验证userId");
			Logger.verifyEquals("200", verifyLoginPwdByLoginIdTypeCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_VerifyLoginPwdByLoginIdType_002() {
		Logger.start(false,"密码错误,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid=JUserCallService.createUserCall(cur);
			verifyLoginPwdByLoginIdReq.setAppId("autotest");
			verifyLoginPwdByLoginIdReq.setClientIp(cur.getClientIp());
			verifyLoginPwdByLoginIdReq.setLoginId(cur.getLoginId());
			verifyLoginPwdByLoginIdReq.setPwd(cur.getLoginPassword()+1);
			verifyLoginPwdByLoginIdTypeCall.setData(verifyLoginPwdByLoginIdReq);
			verifyLoginPwdByLoginIdTypeCall.callService();
			Logger.verifyEquals("false", verifyLoginPwdByLoginIdTypeCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200003", verifyLoginPwdByLoginIdTypeCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("用户名或密码错误", verifyLoginPwdByLoginIdTypeCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_VerifyLoginPwdByLoginIdType_003() {
		Logger.start(false,"用户不存在,失败");
		try {
			verifyLoginPwdByLoginIdReq.setAppId("autotest");
			verifyLoginPwdByLoginIdReq.setClientIp("");
			verifyLoginPwdByLoginIdReq.setLoginId("404NOTFOUND");
			verifyLoginPwdByLoginIdReq.setPwd("111111");
			verifyLoginPwdByLoginIdTypeCall.setData(verifyLoginPwdByLoginIdReq);
			verifyLoginPwdByLoginIdTypeCall.callService();
			Logger.verifyEquals("false", verifyLoginPwdByLoginIdTypeCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200001", verifyLoginPwdByLoginIdTypeCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("用户名或密码错误", verifyLoginPwdByLoginIdTypeCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_VerifyLoginPwdByLoginIdType_004() {
		Logger.start(false,"不输入密码,失败");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid=JUserCallService.createUserCall(cur);
			verifyLoginPwdByLoginIdReq.setAppId("autotest");
			verifyLoginPwdByLoginIdReq.setClientIp(cur.getClientIp());
			verifyLoginPwdByLoginIdReq.setLoginId(cur.getLoginId());
//			verifyLoginPwdByLoginIdReq.setPwd(cur.getLoginPassword()+1);
			verifyLoginPwdByLoginIdTypeCall.setData(verifyLoginPwdByLoginIdReq);
			verifyLoginPwdByLoginIdTypeCall.callService();
			Logger.verifyEquals("false", verifyLoginPwdByLoginIdTypeCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200003", verifyLoginPwdByLoginIdTypeCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("用户名或密码错误", verifyLoginPwdByLoginIdTypeCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_VerifyLoginPwdByLoginIdType_005() {
		Logger.start(false,"不输入用户名,失败");
		try {
			verifyLoginPwdByLoginIdReq.setAppId("autotest");
//			verifyLoginPwdByLoginIdReq.setLoginId(cur.getLoginId());
			verifyLoginPwdByLoginIdReq.setPwd(JUserCallService.defaultLoginPwd);
			verifyLoginPwdByLoginIdTypeCall.setData(verifyLoginPwdByLoginIdReq);
			verifyLoginPwdByLoginIdTypeCall.callService();
			Logger.verifyEquals("false", verifyLoginPwdByLoginIdTypeCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200001", verifyLoginPwdByLoginIdTypeCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("用户名或密码错误", verifyLoginPwdByLoginIdTypeCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_VerifyLoginPwdByLoginIdType_006() {
		Logger.start(true,"验证登入密码,密码加密,成功");
		try {
			CreateUserReq cur=new CreateUserReq();
			cur=JUserCallService.initCreateUserBean(cur);
			Integer uid=JUserCallService.createUserCall(cur);
			verifyLoginPwdByLoginIdReq.setPasswordType(1);
			verifyLoginPwdByLoginIdReq.setAppId("autotest");
			verifyLoginPwdByLoginIdReq.setClientIp(cur.getClientIp());
			verifyLoginPwdByLoginIdReq.setLoginId(cur.getLoginId());
			verifyLoginPwdByLoginIdReq.setPwd(DesUtil.encrypt(cur.getLoginPassword(),DesUtil.DES_KEY_STRING,DesUtil.DES_IVPARAMETER));
			verifyLoginPwdByLoginIdTypeCall.setData(verifyLoginPwdByLoginIdReq);
			verifyLoginPwdByLoginIdTypeCall.callService();
			Logger.verifyEquals("true", verifyLoginPwdByLoginIdTypeCall.getString("Success"), "验证Success");
			Logger.verifyEquals(uid, verifyLoginPwdByLoginIdTypeCall.getJsonObject().get("Result").getAsJsonObject().get("userId").getAsInt(), "验证userId");
			Logger.verifyEquals("200", verifyLoginPwdByLoginIdTypeCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}